﻿using System;
using System.Collections;

using IBatisNet.DataAccess;

using MT.eVotePRS.Model;
using MT.eVotePRS.Service;
using MT.eVotePRS.Persistence.Interfaces;

namespace MT.eVotePRS.Service
{
    public class InventoryTableService
    {
        #region Private Fields
        private static InventoryTableService _instance = new InventoryTableService();
        private IDaoManager _daoManager = null;
        private IInventoryTableDao _inventoryTableDao = null;

        #endregion

        #region Constructor
        private InventoryTableService()
        {
            _daoManager = ServiceConfig.GetInstance().DaoManager;
            _inventoryTableDao = _daoManager.GetDao(typeof(IInventoryTableDao)) as IInventoryTableDao;
        }

        #endregion

        public static InventoryTableService GetInstance()
        {
            return _instance;
        }

        public object InsertInventory(InventoryTable inventory)
        {
            object obj = null;

            _daoManager.BeginTransaction();
            try
            {
                obj = _inventoryTableDao.InsertInventory(inventory);
                _daoManager.CommitTransaction();
            }
            catch
            {
                _daoManager.RollBackTransaction();
                throw;
            }
            return obj;

        }

        public InventoryTable CheckHandset(string handsetId)
        {
            InventoryTable inventTable = null;
            
            _daoManager.OpenConnection();
            inventTable = _inventoryTableDao.CheckHandset(handsetId);
            _daoManager.CloseConnection();

            return inventTable;
        }

        public IList GetAllInventory()
        {
            return _inventoryTableDao.GetAllInventoryList();
        }

    }
}
